package com.chasel.demo.devbox.config;

import com.chasel.demo.devbox.cache.DistributedLockComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author XieLongzhen
 * @date 2019/3/22 11:45
 */
@Configuration
@ConditionalOnClass(DistributedLockComponent.class)
@EnableConfigurationProperties({DistributedLockProperties.class})
public class DevToolAutoConfiguration {
    @Autowired
    private DistributedLockProperties distributedLockProperties;

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "dev-box.distributed-lock", value = "enabled", havingValue = "true")
    public DistributedLockComponent distributedLockComponent() {
        return new DistributedLockComponent(distributedLockProperties.getPrefixKey());
    }
}
